package org.freemarker.core.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "tbl_car")
public class Car extends BaseEntity {
	private static final long serialVersionUID = 942555157742087241L;

	public Car() {

	}

	public Car(String model, String marca, String numarMatricol) {
		super();
		this.model = model;
		this.marca = marca;
		this.numarMatricol = numarMatricol;
	}

	@Column(name = "numar_matricol", nullable = false, unique = true)
	private String numarMatricol;
	
	@Column(name = "model", nullable = false)
	private String model;

	@Column(name = "marca", nullable = false)
	private String marca;
	
	@Column(name = "imageName", nullable = true)
	private String imageName;


	
	@Override
	public String toString() {
		return "Car [numarMatricol=" + numarMatricol + ", model=" + model
				+ ", marca=" + marca + ", imageName=" + imageName
				+ ", contact=" + contact + "]";
	}

	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE},fetch = FetchType.EAGER)
	@JoinColumn(name="contact_id", nullable=true, unique=false)
	private Contact contact;

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getMarca() {
		return marca;
	}

	public void setMarca(String marca) {
		this.marca = marca;
	}

	public String getNumarMatricol() {
		return numarMatricol;
	}

	public void setNumarMatricol(String numarMatricol) {
		this.numarMatricol = numarMatricol;
	}
	
	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		this.imageName = imageName;
	}

	/*
	 * public Contact getContact() { return contact; }
	 * 
	 * public void setContact(Contact contact) { this.contact = contact; }
	 */

	/*
	 * @Column(name = "CAR_ID")
	 * 
	 * @Override public Long getId() { return id; }
	 */

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((marca == null) ? 0 : marca.hashCode());
		result = prime * result + ((model == null) ? 0 : model.hashCode());
		result = prime * result
				+ ((numarMatricol == null) ? 0 : numarMatricol.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Car other = (Car) obj;
		if (marca == null) {
			if (other.marca != null)
				return false;
		} else if (!marca.equals(other.marca))
			return false;
		if (model == null) {
			if (other.model != null)
				return false;
		} else if (!model.equals(other.model))
			return false;
		if (numarMatricol == null) {
			if (other.numarMatricol != null)
				return false;
		} else if (!numarMatricol.equals(other.numarMatricol))
			return false;
		return true;
	}

}
